<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="../common/base.jsp" %>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
    <meta http-equiv="expires" content="0">
    <title>优惠券</title>
    <link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
    <link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
    <style>
        #quxiao {
            width: 90%;
            margin: 0 auto;
            text-align: center;
            color: #4f5a67;
            border-radius: 4px;
            border: solid 1px #4f5a67;
            line-height: 40px;
            height: 40px;
            font-size: 20px;
            margin-bottom: 10px;
        }

        #queren {
            width: 90%;
            margin: 0 auto;
            margin-top: 10px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            border-radius: 4px;
            background-color: #4f5a67;
            font-size: 20px;
            color: #fff;
        }

        .btns-sub {
            position: fixed;
            left: 0;
            right: 0;
            bottom: 0;
            background: #fff;
            padding-bottom: 10px;
        }

        .c-coupon {
            padding-bottom: 120px;
        }
    </style>
</head>
<body class="c-coupon">
<div class="l-coupon">
    <div class="m-coupon">
        <div class="coupon-first">
            <input type="radio" name="test" value="" id="not" class="e-radio">
            <label for="not">
                <span>不使用电子券</span>
                <%--<span style="text-align: right; padding-right: 10px;"><input type="radio" name="test"></span>--%>
            </label>
        </div>
        <ul class="coupon-ul" id="coupon-ul">

        </ul>
    </div>
</div>
<div class="btns-sub">
    <div id="quxiao">取消</div>
    <div id="queren">确认</div>
</div>

<script type="text/html" id="order-list-html">
    <li>
        <input type="radio" name="test" id="{{uuid}}" value="{{uuid}}" checked="checked" class="e-radio">
        <label for="{{uuid}}">
            <div class="coupon-money">
                <p>{{moneys}}<span>{{typeName}}</span></p>
            </div>
            <div class="fenge-y">
                <div></div>
            </div>
            <div class="coupon-text">
                <p>{{name}}</p>
                <div>
                    <p>有效期至{{useEndTime}}</p>
                    <p>{{astrictStr}}</p>
                    <p>{{cityNames}}</p>
                </div>
            </div>
        </label>
    </li>
</script>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<script type="text/javascript" src="${base}/js/localStorageOpt.js"></script>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script>
    (function () {
        var yun = new yueajax("${openId}");
        yun.listHtml = $('#order-list-html').html();
        yun.listCoupon = {};
        var coupon = {
            typeTrip: getQueryString('typeTrip'),
            totalFare: getQueryString('totalFare'),
            originCityUuid: getQueryString('originCityUuid'),
        };
        var couponUuid = getQueryString("couponUuid") || '';
        console.log(getQueryString("couponUuid"))
        yun.ajax_md5(
            coupon,
            '${base}/api/v1/passenger/token/coupon/listPay',
            function (data) {
                var h = ''
                var d = data.data;
                for (var i = 0; i < d.length; i++) {
                    var di = d[i];
                    di.cityNames = !di.cityNames ? '不限城市' : '限' + di.cityNames + '使用';
                    if (di.type == 1) {
                        di.moneys = di.money;
                        di.astrictStr = di.astrict != null ? '单笔满' + di.astrict + '使用' : '无门槛';
                        di.typeName = '元';
                    } else {
                        di.typeName = '折';
                        di.moneys = di.discount;
                        di.astrictStr = '';
                        if (di.astrict != null) {
                            di.astrictStr += '单笔满' + di.astrict + '使用';
                        }
                        if (di.highestMoney != null) {
                            di.astrictStr += ',最高抵扣' + di.highestMoney + '元';
                        }
                        if (di.astrict == null || di.highestMoney == null) {
                            di.astrictStr = "无门槛"
                        }
                    }
                    di.useEndTime = (new Date(di.useEndTime)).format('YYYY-MM-DD');
                    h += yun.rendering(yun.listHtml, di);
                    yun.listCoupon[di.uuid] = di;
                }
                $('#coupon-ul').html(h);
                if (couponUuid != "") {
                    $('[for=' + getQueryString("couponUuid") + ']').click();
                } else {
                    $('#not').click();
                }
            },
            function (data) {
                layer.msg(data.msg)
            }
        );
        var wt = window.top;
        $('#queren').click(function () {
            var di = $('.e-radio:checked').val();
            wt.setCouInfo(yun.listCoupon[di] || null);
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        });
        $('#quxiao').click(function () {
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        })

    })()
</script>
</body>
</html>
